package com.googlecode.moneyManager.dao.hib;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

import com.googlecode.moneyManager.model.*;

/**
 * 
 * @author Sergiy Doroshenko Jul 15, 2008 12:19:00 AM
 */
@Deprecated
public class HibernateUtil {
    private static final SessionFactory sessionFactory;
    static {
	try {
	    sessionFactory = new AnnotationConfiguration()
	   // Deposit.class.getPackage().getName()
	    .addPackage("com.googlecode.moneyManager.model")
	    .addAnnotatedClass(App.class)
	    .addAnnotatedClass(Percentage.class)
	     .addAnnotatedClass(Amount.class)
	    .addAnnotatedClass(Replenish.class)
	    .addAnnotatedClass(Branch.class)
	    .addAnnotatedClass(Bank.class)
	    .addAnnotatedClass(Customer.class)
	    .addAnnotatedClass(Address.class)
	    .addAnnotatedClass(Deposit.class)
	    .addAnnotatedClass(SecurityValue.class)
	    .configure()
	    .buildSessionFactory();
	} catch (Throwable ex) {
        ex.printStackTrace();
	    throw new ExceptionInInitializerError(ex);
	}
    }

    public static Session getSession() throws HibernateException {
	    return sessionFactory.getCurrentSession();
    }

    public static SessionFactory getSessionFactory() {
	    return sessionFactory;
    }
}
